// ==UserScript==
// @name YouTube - force player quality; disables autoplay;  
// @include *youtube.com/watch*
// @author   Drozdman
// ==/UserScript==

(function (window, document) {

var quality="medium";
//qualities: "hd720"="720p"; "large"="480p"; "medium"="360p"; "small"="240p"; "tiny"="144p"



YT_player=function(){ 

    var player=document.getElementById('movie_player') || document.getElementById('movie_player-flash') || document.getElementById('movie_player-html5') || document.getElementById('movie_player-html5-flash')  || document.embeds[0];

    var player_new=player.cloneNode(true);
    var flashvars=player.getAttribute("flashvars");
    var flashvars_new=flashvars.replace('vq=auto','vq='+quality).replace(/watermark=[^&]*/,'') + 
    "&autoplay=0&autohide=0" + 
    "&theme=dark&color=red&iv_load_policy=3&disablekb=1&enablejsapi=1";  
    //flashvars_new+="&dash=0"; // force buffering, not for 144p, 1080p


    player_new.setAttribute("flashvars",flashvars_new);

    player.parentNode.replaceChild(player_new,player)

} 

window.addEventListener('DOMContentLoaded',YT_player) 


})(window, window.document)


//=========================================================================
/* 

qualities: "hd720"="720p"; "large"="480p"; "medium"="360p"; "small"="240p"; "tiny"="144p"

&autoplay=0
&autohide=0  ; video controls hide
&theme=dark&color=red
&iv_load_policy=3   ;video annotations not shown by default
&enablejsapi=1  
&disablekb=1 -  disable shortcut keys

*/


